<div class="layui-container fly-marginTop fly-user-main">
  {include file='common/menu'/}

  <div class="fly-panel fly-panel-user" pad20>
    <!--
      <div class="fly-msg" style="margin-top: 15px;">
        您的邮箱尚未验证，这比较影响您的帐号安全，<a href="activate.html">立即去激活？</a>
      </div>
      -->
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title" id="LAY_mine">
        <li data-type="mine-jie" lay-id="index" class="{$flag == 'collected' ? 'layui-this' : ''}">我发表的帖（<span>{$userPost|count}</span>）</li>
        <li data-type="collection" data-url="/collection/find/" lay-id="collection" class="{$flag == 'collection' ? 'layui-this' : ''}">我收藏的帖（<span>{$postList|count}</span>）</li>
      </ul>
      <div class="layui-tab-content" style="padding: 20px 0;">
        {php}if($flag == '')$flag = 'collected';{/php}
        <div class="layui-tab-item {$flag == 'collected' ? 'layui-show' : ''}">
          <ul class="mine-view jie-row">
            {foreach $userPost as $item}
            <li>
              <a class="jie-title" href="{:url('home/index/info',['postid' => $item.id])}" target="_blank">{$item.title}</a>
              <i>{$item.createtime}</i>
              <a class="mine-edit" href="{:url('home/post/edit',['postid' => $item.id])}"
                style="float: right;margin-right: 100px;">编辑</a>
              <em>{$item['visit_count']}阅/{$item['comment_count']}答</em>
            </li>
            {/foreach}
          </ul>
          {$userPost->render()}
          <div id="LAY_page"></div>
        </div>
        <div class="layui-tab-item {$flag == 'collection' ? 'layui-show' : ''}">
          <ul class="mine-view jie-row">
            {foreach $postList as $item}
            <li>
              <a class="jie-title" href="{:url('home/index/info',['postid' => $item.post.id])}" target="_blank">{$item.post.title}</a>
              <i>{$item.createtime}</i>
              <a class="mine-edit layui-bg-red Cancel_collect" href="javascript:;" data-id="{$item.id}"
                style="float: right;margin-right: 100px;">取消收藏</a>
            </li>
            {/foreach}
          </ul>
          {$postList->render()}
          <div id="LAY_page1"></div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  layui.use(['layer'], function () {
    let $ = layui.jquery,
      layer = layui.layer
    //取消收藏
    $('.Cancel_collect').click(function () {
      let collectId = $(this).data('id')

      //发起请求
      $.ajax({
        type: 'post',
        url: `{:url('home/post/collect')}`,
        data: {
          collectId,
          action: "cancel"
        },
        dataType: 'json',
        success: function (res) {
          if (res.code === 1) {
            layer.msg(res.msg, { icon: 1 }, function (index) {
              location.href = "/home/user/collect.html";
            })
          } else {
            layer.msg(res.msg, { icon: 5 })
          }
        }
      })
    })
  })
</script>